package main

import (
	"fmt"
	"os"
	"bufio"
	"io"
)

func main(){
	//文件复制
	file_path,_ := os.Getwd()
	file_url := file_path + "/Test.txt"
	file,open_err := os.Open(file_url)

	if open_err != nil{
		fmt.Println("文件打开失败：",open_err)
		return
	}

	defer file.Close()

	//读取文件流
	content := bufio.NewReader(file)

	w_file,w_err := os.OpenFile(file_path + "/Demo.txt",os.O_RDWR|os.O_APPEND|os.O_CREATE,0644)
	if w_err != nil{
		fmt.Println("写入文件初始化失败：",w_err)
		return
	}

	defer w_file.Close()

	write_file := bufio.NewWriter(w_file)
	fmt.Println(write_file)

	for{
		str,str_err := content.ReadString('\n')
		if str_err == io.EOF{
			break
		}

		if str_err != nil {
			fmt.Println("文件读取错误：",str_err)
			return
		}

		write_file.WriteString(str)
		fmt.Println(str)
	}

	write_file.Flush()
	fmt.Println("文件读取完成")
}